package org.itboys.core.util;

import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.commons.utils.servlet.ServletContextHolder;


/**
 * 常用应答消息
 */
public class ResponseMessage {


	/**
	 * 成功
	 */
	public static void success() {
		AjaxUtils.renderJson(ServletContextHolder.getResponse(),
				ResultPageDOHelper.getMsgResultDO(CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));
	}

	/**
	 * 成功 并带有返回结果
	 * @param obj
     */
	public static void success(Object obj) {
		AjaxUtils.renderJson(ServletContextHolder.getResponse(),
				ResultPageDOHelper.getMsgResultDO(obj,  CommonConstants.SUCCESS));
	}

	/**
	 * 失败/错误
	 * @param code
	 * @param message
     */
	public static void error(Integer code, String message){
		AjaxUtils.renderJson(ServletContextHolder.getResponse(),
				ResultPageDOHelper.getErrorResultDO(code, message));
	}
	/**
	 * 失败/错误
	 * @param message
	 */
	public static void error( String message){
		AjaxUtils.renderJson(ServletContextHolder.getResponse(),
				ResultPageDOHelper.getErrorResultDO(-1, message));
	}
	/**
	 * 系统错误
	 */
	public static void systemError() {
		AjaxUtils.renderJson(ServletContextHolder.getResponse(),
				ResultPageDOHelper.getErrorResultDO(CommonConstants.FAIL_CODE, CommonConstants.ERROMSG));
	}

	/**
	 * token已过期
	 */
	public static void tokenExpires(){
		AjaxUtils.renderJson(ServletContextHolder.getResponse(),
				ResultPageDOHelper.getErrorResultDO(40005, "TOKEN已过期"));
	}

	/**
	 * 头部参数错误
	 */
	public static void headError(){
		AjaxUtils.renderJson(ServletContextHolder.getResponse(),
				ResultPageDOHelper.getErrorResultDO(40006, "头部参数错误"));
	}

	/**
	 * 签名错误
	 */
	public static void signError(){
		AjaxUtils.renderJson(ServletContextHolder.getResponse(),
				ResultPageDOHelper.getErrorResultDO(40007, "签名校验失败"));
	}

	/**
	 * 参数错误
     */
	public static void errorParam() {
		AjaxUtils.renderJson(ServletContextHolder.getResponse(),
				ResultPageDOHelper.getErrorResultDO(40008, "参数不全或传参不合法"));
	}

	/**
	 * 请求已失效
	 */
	public static void invalidUrl() {
		AjaxUtils.renderJson(ServletContextHolder.getResponse(),
				ResultPageDOHelper.getErrorResultDO(40010, "请求已失效"));
	}

	/**
	 * 登录失败
	 */
	/*public static void loginFail() {
		AjaxUtils.renderJson(ServletContextHolder.getResponse(),
				ResultPageDOHelper.getErrorResultDO(LOGIN_FAILE, "登录失败"));
	}*/


}
